const {handleCount,handleTime} = require("../../utils/index")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    arr:"",
    res:"",
    playStates:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let {id} = options
    wx.request({
      url: `http://192.168.4.18:3000/playlist/detail?id=${id}`,
      header: {'content-type':'application/json'},
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (result)=>{
        var arr = result.data.playlist
        arr.playCount = handleCount(arr.playCount)
        arr.subscribedCount = handleCount(arr.subscribedCount)
        arr.commentCount = handleCount(arr.commentCount)
        arr.shareCount = handleCount(arr.shareCount)
        var res = arr.tracks
        res.forEach(item=>{
          item.dt = handleTime(item.dt)
        })
        this.setData({
          arr,
          res
        })
      }
    });
  },
 
  handlePlay(event){
    let id = event.currentTarget.dataset.aid;
    let playStates = this.data.playStates;
    playStates[id] = !playStates[id]
    for(let key in playStates){
      if(key != id){
        playStates[key] = false
      }
    }
    this.setData({
      playStates
    })
  }
})